package shiro.com.service.file.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import shiro.com.domain.file.FileUp;
import shiro.com.domain.file.UserFileupComont;
import shiro.com.domain.file.vo.FileUpVo;
import shiro.com.mapper.file.FileUpMapper;
import shiro.com.mapper.file.UserFileUpMapper;
import shiro.com.mapper.file.UserFileupComontMapper;
import shiro.com.service.file.IFileUpService;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2022-12-12
 */
@Service
public class FileUpServiceImpl implements IFileUpService
{
    @Autowired
    private FileUpMapper fileUpMapper;
    @Autowired
    private UserFileupComontMapper userFileupComontMapper;
    @Autowired
    private UserFileUpMapper userFileUpMapper;
    /**
     * 查询【请填写功能名称】
     *
     * @param fileUpId 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public FileUp selectFileUpById(Long fileUpId)
    {
        return fileUpMapper.selectFileUpById(fileUpId);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param fileUp 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<FileUp> selectFileUpList(FileUp fileUp)
    {
        List<FileUp> fileUps = fileUpMapper.selectFileUpList(fileUp);

        return fileUps;
    }


    @Override
    public Map<String, List<String>> selectFileUpGetMothList(FileUp fileUp)
    {
        List<FileUp> fileUps = fileUpMapper.selectFileUpList(fileUp);
        Map<String, List<String>> collect = fileUps.stream().map(item -> {
            return item.getFileUpTime().split("-")[0]+"-"+item.getFileUpTime().split("-")[1];
        }).collect(Collectors.groupingBy(item -> {

            return item;
        }));

        return collect;
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param fileUp 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertFileUp(FileUp fileUp)
    {
        fileUpMapper.insertFileUp(fileUp);


        return  fileUp.getFileUpId().intValue();
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param fileUp 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateFileUp(FileUp fileUp)
    {
        return fileUpMapper.updateFileUp(fileUp);
    }



    /**
     * 批量删除【请填写功能名称】
     *
     * @param fileUpIds 需要删除的【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteFileUpByIds(Long[] fileUpIds)
    {
        System.out.println(fileUpIds);
        List<Integer> collect = Arrays.stream(fileUpIds).map(item -> {
            return item.intValue();
        }).collect(Collectors.toList());
        Integer[] integers2 = collect.toArray(new Integer[0]);

        userFileupComontMapper.deleteUserFileupComontByFileIds(integers2);
        userFileUpMapper.deleteUserFileUpByFileIds(integers2);
        return fileUpMapper.deleteFileUpByIds(fileUpIds);
    }
    @Override
    public int deleteFileUpByIds2(Long fileUpIds)
    {
        return fileUpMapper.deleteFileUpByIds2(fileUpIds);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param fileUpId 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteFileUpById(Long fileUpId)
    {
        return fileUpMapper.deleteFileUpById(fileUpId);
    }

    @Override
    public List<FileUpVo> selectNameByPhone(String phone){

        List<FileUpVo> strings = fileUpMapper.selectNameByPhone(phone);

        return strings;
    }
}
